package com.practice;

import java.util.ArrayList;
import java.util.List;

public class MultithreadPractice implements IPractice {

	@Override
	public void run() {

		TestThread thread = new TestThread();
		thread.start();
		
		
		while (true) {
			System.out.println("Main thread.");
			try {
				Thread.sleep(2000);
			} catch (InterruptedException ex){
				System.out.println(ex.getMessage());
			}
		}
	}
	
}

class TestThread extends Thread {
	private List<Integer> list;
	
	public TestThread() {
		int count = 8;
		list = new ArrayList<>(count);
		for (int i = 0; i < count; i++) {
			list.add(i);
		}
	}
	
	@Override
	public void run() {
		while (true) {
			Integer value = list.get(0);
			list.remove(0);
			System.out.println(value);
			try {
				sleep(800);
			} catch (InterruptedException ex) {
				System.out.println(ex.getMessage());
			}
		}
	}
}
